slicemax=max(aarr[*,*,*])
slicemin=min(aarr[*,*,*])
iend=(size(aarr))[3]
nl=60

Lz=1.4
Lx=5.0
nz=240
nx=120
zarray=(Lz/nz)*indgen(nz)
xarray=(Lx/nx)*indgen(nx)


levgeral=grange(slicemin,slicemax,nl)
;setting the same max and min levels for all the slices 
;levgeral=grange(min(aarr[*,*,*]),max(aarr[*,*,*]),nl)
for ii=ibeg,iend-1 do begin
 DEVICE, GET_DECOMPOSED=old_decomposed
 DEVICE, DECOMPOSED=0
 ;setting levels for each slice, they are in general different.
 ;lev=grange(min(aarr[*,*,ii]),max(aarr[*,*,ii]),nl)
 if extension eq 'yz' then begin
  contour, aarr[*,*,ii], /fi, nl=nl, lev=levgeral
 endif
 if extension eq 'xy' then begin
  contour, aarr[*,*,ii], /fi, nl=nl,/iso,lev=levgeral
 endif
 if extension eq 'xz' then begin
  contour, aarr[*,*,ii], xarray, zarray,/iso, /fi, nl=nl,lev=levgeral
  colorbar, range=[slicemin,slicemax], /horizontal, pos=[0.77,0.1,0.87,0.95], xtickformat='(F6.1)', xaxis=2, charsize=1.5
 endif
 ;window, 1, xsize=300, ysize=300
 ;tv, image
 ; saving image in a png file
 istr = strtrim(string(ii,'(I20.4)'),2)
 imagename = './img_'+istr+'.png'
 print, "writing png ", imagename
 WRITE_PNG, imagename, TVRD(/TRUE), red, green, blue   
 wait,0
endfor

end
